﻿#include "msaddmandialog.h"
#include "ui_msaddmandialog.h"
#include <QtSql>

MSaddmanDialog::MSaddmanDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MSaddmanDialog)
{
    ui->setupUi(this);
    ui->frame->resize(this->geometry().width(), ui->frame->height());
    ui->status->setText("添加信息状态：");
    ui->dateEdit->setDate(QDate::currentDate());
    connect(ui->cancelbtn,SIGNAL(clicked(bool)),this,SLOT(close()));
    connect(ui->ackbtn,SIGNAL(clicked(bool)),parent,SLOT(MSshowdatabase()));
}

MSaddmanDialog::~MSaddmanDialog()
{delete ui;}

void MSaddmanDialog::on_ackbtn_clicked()
{
    if(ui->unit->text().isEmpty()||ui->send->text().isEmpty()||ui->copies->text().isEmpty()){
        ui->status->setText("添加信息状态:请至少添入报送日期，报送单位，报送人，份数");
    }
    else {

    QSqlQuery query;
    query.prepare("INSERT INTO ZZB.MaterialSend(SendID,SendDate,SendUnit,SendMan,Receive,ReceivePhone,Envelope,Copies)"
                  "VALUES(:SendID,:SendDate,:SendUnit,:SendMan,:Receive,:ReceivePhone,:Envelope,:Copies)");
    query.bindValue(":SendDate",ui->dateEdit->text());
    query.bindValue(":SendlUnit",ui->unit->text());
    query.bindValue(":Copies",ui->copies->text());
    query.bindValue(":SendMan",ui->send->text());
    query.bindValue(":Receive",ui->receiver->text());
    query.bindValue(":ReceivePhone",ui->phone->text());
    query.bindValue(":Envelope",ui->envelope->text());

    bool ok=query.exec();
    if(ok)
    {ui->status->setText("添加信息状态:添加成功");
            this->close();}
    else{ui->status->setText("添加信息状态:添加失败");}
}
}
